package com.qlh.composewidget.useage

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.feeyo.groundservice.easyphoto.EasyPhotos
import com.feeyo.groundservice.easyphoto.R
import com.feeyo.groundservice.easyphoto.callback.SelectCallback
import com.feeyo.groundservice.easyphoto.models.album.entity.Photo

/**
 *作者：70893 on 2024-12-14
 *描述：
 */
class TestEasyPhoto : AppCompatActivity() {

    private val fileProvider = "com.qlh.composewidget.FileProvider"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test_easy_photo)
    }


    fun openSingleAlbum(view: View) {

        //相册单选，无相机功能
        EasyPhotos.createAlbum(this, false, false, GlideEngine.getInstance())
            .start(101) //也可以选择链式调用写法
    }

    fun openSingleCamera(view: View) {
        //单独使用相机
        EasyPhotos.createCamera(this, true)
            .setFileProviderAuthority(fileProvider)
            .start(101) //也可以选择链式调用写法
    }

    fun openMultiAlbum(view: View) {

        //相册多选，无相机功能
        EasyPhotos.createAlbum(this, false, false, GlideEngine.getInstance())
            .setCount(2)
            .start(101) //也可以选择链式调用写法
    }

    fun openMultiAlbumCamera(view: View) {
        EasyPhotos.createAlbum(this, true, false, GlideEngine.getInstance())
            .setFileProviderAuthority(fileProvider)
            .setCount(2)
            .start(object : SelectCallback() {
                override fun onResult(photos: ArrayList<Photo>?, isOriginal: Boolean) {
                    Log.e("直接回调结果", photos?.get(0)?.path ?: "")
                }

                override fun onCancel() {

                }
            })
    }

    fun openSingleAlbumCamera(view: View) {

        //相册单选，有相机功能
        EasyPhotos.createAlbum(this, true, false, GlideEngine.getInstance())
            .setFileProviderAuthority(fileProvider)
            .start(101) //也可以选择链式调用写法
    }

    fun openSingle(view: View) {

        //相册中不显示底部的编辑图标按钮
        EasyPhotos.createAlbum(this, true, false, GlideEngine.getInstance())
            .setFileProviderAuthority(fileProvider)
            .setCount(9)
            .setPuzzleMenu(false)
            .setCleanMenu(false)
            .start(101)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        Log.e("resultPhotos", resultCode.toString())
        if (RESULT_OK == resultCode) {
            //相机或相册回调
            if (requestCode == 101) {
                //返回对象集合：如果你需要了解图片的宽、高、大小、用户是否选中原图选项等信息，可以用这个
                val resultPhotos =
                    data?.getParcelableArrayListExtra<Photo>(EasyPhotos.RESULT_PHOTOS)
                Log.e("resultPhotos", resultPhotos?.get(0)?.path ?: "")
            }
        }
    }
}